#ifndef __USER_MGR_H__
#define __USER_MGR_H__

#include "Protocal/Common.pb.h"
#include "DbExecute.h"

class CAsioTcpLink;

class CUser : public xObjBase
{
public:
	CUser( U64 uGuid );

	void Save2DB();
	void LoadRoleList();
	void DestroyOldNet();
	void SendKeyRCmd();
//	void UpdateOnlineTime();

	BOOL HaveRole(U64 role_id);
public:
	MYTH::User		user;
	DECLARE_VAR(U64, m_uMagicID);
	DECLARE_VAR(U64, m_uRole_ID);
};

/// Login no user_id
class CLoginUser : public xBase
{
public:
	CLoginUser();
};

class CUserMgr
{
	SINGLETON_CLASS(CUserMgr)
protected:
	CUserMgr();
	virtual ~CUserMgr();

public:
	void AddLoginUser(const std::string& str_account, CAsioTcpLink* pLink);
	void RemoveLoginUser(const std::string& str_account);
	CLoginUser* GetLoginUser(const std::string& str_account);

	void LoadFromDB();
	CUser* LoadUserFromDB(U64 uGuid);
	CUser* LoadUserFromDB(const std::string& str_account);
	CUser* getUser(const std::string& str_account);
	CUser* GateOnLoginR(MYTH::AccountLogin_R& cmd);
	CUser* CreateUserByKey(MYTH::User_Key& cmd);
protected:
	CUser* CreateUserByDB(const CDbExecute::DATA_ROW_MAP& rowData);
protected:
	boost::unordered_map<std::string, CUser*>			m_mapUsers;
	boost::unordered_map<std::string, CLoginUser*>		m_mapLoginUser;
};

#endif //__USER_MGR_H__